package com.wanmait.recruitment.Filter;

import com.wanmait.recruitment.util.PageContext;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter("/*")
public class PageFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        int pageNum = 1;
        try {
            pageNum=Integer.parseInt(request.getParameter("pageNum"));
        } catch (NumberFormatException e) {
        }
        PageContext.setPageNum(pageNum);
        try {
            chain.doFilter(request, response);
        }
        // 使用完Threadlocal，将其删除。使用finally确保一定将其删除
        finally {
            PageContext.removePageNum();
        }
    }

}